package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Tiaojian;
import com.ruoyi.project.system.service.ITiaojianService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 抢单条件Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@RestController
@RequestMapping("/system/tiaojian")
public class TiaojianController extends BaseController
{
    @Autowired
    private ITiaojianService tiaojianService;

    /**
     * 查询抢单条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tiaojian tiaojian)
    {
        startPage();
        List<Tiaojian> list = tiaojianService.selectTiaojianList(tiaojian);
        return getDataTable(list);
    }

    /**
     * 导出抢单条件列表
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:export')")
    @Log(title = "抢单条件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Tiaojian tiaojian)
    {
        List<Tiaojian> list = tiaojianService.selectTiaojianList(tiaojian);
        ExcelUtil<Tiaojian> util = new ExcelUtil<Tiaojian>(Tiaojian.class);
        return util.exportExcel(list, "tiaojian");
    }

    /**
     * 获取抢单条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(tiaojianService.selectTiaojianById(userId));
    }

    /**
     * 新增抢单条件
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:add')")
    @Log(title = "抢单条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tiaojian tiaojian)
    {
        return toAjax(tiaojianService.insertTiaojian(tiaojian));
    }

    /**
     * 修改抢单条件
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:edit')")
    @Log(title = "抢单条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tiaojian tiaojian)
    {
        return toAjax(tiaojianService.updateTiaojian(tiaojian));
    }

    /**
     * 删除抢单条件
     */
    @PreAuthorize("@ss.hasPermi('system:tiaojian:remove')")
    @Log(title = "抢单条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(tiaojianService.deleteTiaojianByIds(userIds));
    }
}
